/*
 * Part of knowledge engineering (ke) course work, 2010/11
 */
package se.bth.ke.firstfriend.model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;

/**
 *
 * @author nico.rehwaldt
 */
@Entity
@Indexed
public class Comment implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Field(index=Index.TOKENIZED)
    @Column(columnDefinition="LONGTEXT NOT NULL")
    private String content;

    @Temporal(TemporalType.TIMESTAMP)
    private Date createdAt;

    private String author;

    @ManyToOne
    private Article article;

    /**
     * Non-args constructor for persistence layer
     */
    public Comment() {}

    /**
     * Creates a new comment with content and author specified
     * @param content
     * @param author
     */
    public Comment(String author, String content) {
        this.content = content;
        this.author = author;
    }
    
    public Long getId() {
        return id;
    }

    /**
     * @return the content
     */
    public String getContent() {
        return content;
    }

    /**
     * @return the createdAt
     */
    public Date getCreatedAt() {
        return createdAt;
    }

    /**
     * @return the owner
     */
    public String getAuthor() {
        return author;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Comment)) {
            return false;
        }
        Comment other = (Comment) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "se.bth.ke.firstfriend.model.Comment[id=" + id + "]";
    }

    /**
     * @param article the article to be set
     */
    public void setArticle(Article article) {
        this.article = article;
    }
}
